import { createApp } from "vue";
// import { createPinia } from 'pinia';

import pinia from "./stores/pinia.js";

import i18n from "./langs/index.js";

import App from "./App.vue";
import router from "./router";
import "./assets/main.css";

const app = createApp(App);

/*window websocket-----项目按需---*/

import {
  websocket_init,
  websocket_send,
  websocket_send_new,
  websocket_close,
  websocket_reconect,
  websocket_on_message
} from "@/plugins/websocket.js";

app.config.globalProperties.$websocket_init = websocket_init;
app.config.globalProperties.$websocket_send = websocket_send_new;
app.config.globalProperties.$websocket_close = websocket_close;
app.config.globalProperties.$websocket_reconect = websocket_reconect;
app.config.globalProperties.$websocket_on_message = websocket_on_message;

import {
  Popconfirm,
  Checkbox,
  Form,
  Pagination,
  DatePicker,
  Button,
  message,
  Input,
  Layout,
  RadioGroup,
  Radio,
  Select,
  Menu,
  Switch,
  ConfigProvider,
  Modal,
  Empty,
  Table
} from "ant-design-vue";

app.use(Empty);
app.use(Form);
app.use(Checkbox);
app.use(Pagination);
app.use(DatePicker);
app.use(Table);

app.use(Button);
app.use(Input);
app.use(Layout);

app.use(RadioGroup);
app.use(Radio);

app.use(Select);
// app.use(Select.Option);

app.use(Menu);
app.use(Switch);
app.use(Modal);
app.use(Popconfirm);
app.use(Form);
app.use(ConfigProvider);

app.use(router);

app.use(pinia);

app.use(i18n); //使用语言包

app.config.globalProperties.$message = message;
app.config.globalProperties.$Modal = Modal;

app.config.errorHandler = (err, vm, info) => {

  console.log("app全局错误--",err.toString());
  console.log("app全局错误-info-",info.toString());
  // console.log("app全局错误--",err,vm,info);

  // debugger;

  if(err.toString().indexOf('datas')&&window.location.href.indexOf('preview')>-1){
    window.location.reload()
  }
  console.log(err, vm, info); //must 否则路由跳转会再次失效。
  // do something
};



//pinia,router默认已经挂载。ce

app.mount("#app");
